<script lang="ts">
export default {
  name: "DeviceRecordFormHeader"
}
</script>

<template>
  <el-form ref="queryFormRef" :inline="true" :model="dataState.queryParams">
    <el-form-item prop="deviceName">
      <el-input v-model="dataState.queryParams.deviceName" clearable placeholder="设备名称" @keyup.enter="handleQuery"/>
    </el-form-item>

    <el-form-item prop="metricName">
      <el-input v-model="dataState.queryParams.metricName" clearable placeholder="指标名称" @keyup.enter="handleQuery"/>
    </el-form-item>

    <el-form-item prop="metricName">
      <el-date-picker
        v-model="dataState.queryParams.datetime"
        format="YYYY-MM-DD HH:mm:ss"
        placeholder="选择日期时间"
        type="datetime"
        value-format="YYYY-MM-DD HH:mm:ss"
      />
    </el-form-item>


    <el-form-item>
      <el-button :icon="Search" type="primary" @click="handleQuery">搜索</el-button>
      <el-button :icon="Refresh" @click="resetQuery">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script lang="ts" setup>
import {onMounted, reactive} from "vue";


import {Search, Refresh} from '@element-plus/icons-vue';

const emit = defineEmits(['query']);// 定义组件的事件通知

// 数据状态：定义
let dataState = reactive({
  queryParams: {datatime: '',pageNum: 1, pageSize: 10} as any,
});

function handleQuery() {
  if (dataState.queryParams.deviceName != undefined) {
    dataState.queryParams.deviceName = dataState.queryParams.deviceName.trim()
  }
  if (dataState.queryParams.metricName != undefined) {
    dataState.queryParams.metricName = dataState.queryParams.metricName.trim()
  }
  if (dataState.queryParams.datetime != undefined) {
    dataState.queryParams.datetime = dataState.queryParams.datetime.trim()
  }

  emit('query', 'header', dataState.queryParams);
}

function resetQuery() {
  dataState.queryParams.deviceName = undefined;
  dataState.queryParams.metricName = undefined;
  dataState.queryParams.datetime = undefined;
  emit('query', 'header', dataState.queryParams);
}

onMounted(() => {
});

</script>
